<?php
/**
  * 前端文件配置
  *
  * @access public
  * @author virowin<virowin@gmail.com>
  * @version 1.0 Wed Apr 25 15:18:22 CST 2012
  * @package app
  */
//头文件引入
define(VIROWIN,1);
require_once('include.php');

$type = trim(addslashes($_GET['type']));
!$type && $type = 'list';
if($type == 'import'){
    $file = fopen('a.csv','r');
    $count = 0;
    while ($data = fgetcsv($file)) { //每次读取CSV里面的一行内容
        //        print_z($data); //此为一个数组，要获得每一个数据，访问数组下标即可
        $count++;
        if($count == 1) continue;
        foreach ($data as $key=>$per){
            $data[$key] = iconv('GBK','utf-8',$per);
        }
        $array = array();
        $array['teamid'] = $data[1];
        $array['name'] = $data[2].$data[3];
        $array['position'] = $data[4];
        $array['height'] = $data[5];
        $array['weight'] = $data[6];
        $array['age'] = $data[7];
        $array['heavy_foot'] = $data[8];
        $array['heading'] = $data[9];
        $array['strength'] = $data[10];
        $array['speed'] = $data[11];
        $array['strong'] = $data[12];
        $array['energy'] = $data[13];
        $array['agility'] = $data[14];
        $array['dribbling'] = $data[15];
        $array['finishing'] = $data[16];
        $array['first_touch'] = $data[17];
        $array['short_pass'] = $data[18];
        $array['long_pass'] = $data[19];
        $array['marking'] = $data[20];
        $array['tackling'] = $data[21];
        $array['keep_goal'] = $data[22];
        $array['spirit'] = $data[23];
        $array['positioning'] = $data[24];
        $array['off_the_ball'] = $data[25];
        $array['decisions'] = $data[26];
        $array['flair'] = $data[27];
        $array['teamwork'] = $data[28];
        $array['injury_proneness'] = $data[29];
        $array['aggression'] = $data[30];
        $array['composure'] = $data[31];
        $array['tenacity'] = $data[32];
        $array['skill1'] = $data[33];
        $array['salary'] = intval($data[0]);
        //        Data_Player::add_one($array);
        //        echo $array['name'].;
        $array = array();
        //        $array['salary'] = rand(100,1000);
        //        print_z($array);
        //        $goods_list[] = $array;
    }
    fclose($file);
    echo "end";exit();
}elseif($type == 'api'){
    $limit = 50;
    $order_by = intval($_GET['order']);
    $page = intval($_GET['page']);
    $page <1 && $page = 1;
    if($_GET['teamid'] !== ''){
        $teamid = intval($_GET['teamid']);
    }
    //排序方法
    $order_by_list = array("0"=>'id',"1"=>"height","2"=>"weight","3"=>"age","4"=>"heavy_foot","5"=>"heading","6"=>"strength","7"=>"speed","8"=>"strong","9"=>"energy","10"=>"agility","11"=>"dribbling","12"=>"finishing","13"=>"first_touch","14"=>"short_pass","15"=>"long_pass","16"=>"marking","17"=>"tackling","18"=>"keep_goal","19"=>"spirit","20"=>"positioning","21"=>"off_the_ball","22"=>"decisions","23"=>"flair","24"=>"teamwork","25"=>"skill1","26"=>"salary",);
    if(!isset($order_by_list[$order_by])){
        $order_by = $order_by_list[0];
    }else{
        $order_by = $order_by_list[$order_by];
    }
    //筛选条件
    $filter = array();
    if($_GET['teamid'] !== ''){
        $filter['teamid'] = $teamid;
    }
    $list = Biz_Player::getPlayerList($filter,$order_by,$page,$limit);
    echo json_encode($list);
    exit();
    print_z($list);
}elseif ($type == 'list'){
    $smarty = new Lib_SmartyTpl();
    $smarty->add_js('player.js');
    $smarty->assign('player_list',$list);
    $smarty->show('player_list');
}